package com.hdu.hot100.trick;

public class lc169 {
    class Solution {
        public int majorityElement(int[] nums) {

            int vote = 0;
            int ans = 0;

            for (int num : nums)
            {
                if (vote == 0)
                {
                    vote++;
                    ans = num;
                }
                else
                {
                    if (num != ans)
                    {
                        vote--;
                    }
                    else
                    {
                        vote++;
                    }
                }
            }

            return ans;
        }
    }
}
